public class Test5 {
    public static void main(String[] args) {
        Car[] cars = {new Passagecar(1, "AudiA4", 5),
                new Passagecar(2, "Wuling", 7)};

        int sum = 0;

        for (Car c : cars) {
            if (c instanceof Passagecar) {
                Passagecar p = (Passagecar)c;
                sum += p.getHumanNum();
            }
        }
        System.out.println(sum);
    }
}

abstract class Car {
    private int carId;

    private String carName;

    public Car(int carId, String carName) {
        this.carId = carId;
        this.carName = carName;
    }

    public int getCarId() {
        return carId;
    }

    public String getCarName() {
        return carName;
    }

    public abstract String getCapacity();//抽象方法，和接口中定义相同
}

interface IHumanNum {
    public abstract int getHumanNum();

    public abstract void setHumanNum(int humanNum);

}

class Passagecar extends Car implements IHumanNum {
    private int humanNum;

    public Passagecar(int carId, String carName, int humanNum) {
        super(carId, carName);
        this.humanNum = humanNum;
    }

    @Override
    public int getHumanNum() {
        return humanNum;
    }

    @Override
    public void setHumanNum(int humanNum) {
        this.humanNum = humanNum;
    }

    @Override
    public String getCapacity() {
        return "车载数: " + this.getHumanNum() + "人";
    }
}